package org.example.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.example.demo.config.R;
import org.example.demo.entity.Goods;
import org.example.demo.entity.Seller;
import org.example.demo.exception.SssException;
import org.example.demo.service.GoodsService;
import org.example.demo.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lining
 * @since 2023-12-02
 */
@RestController
@RequestMapping("/demo/category")
public class CategoryController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private SellerService sellerService;


    @ApiOperation("根据卖家id查卖家物品")
    @GetMapping("info/{id}")
    public R infoById(@PathVariable Long id){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        QueryWrapper<Goods> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("seller_id",id);
        List<Goods> list=goodsService.list(queryWrapper);
        if (StringUtils.isEmpty(list)) {
            throw new SssException(201, "数据信息为空");
        }
        return R.ok().data("lists", list);
    }



    @ApiOperation("根据物品id查询卖家名字")
    @GetMapping("info1/{id}")
    public R infoBySeller(@PathVariable Long id){
        Goods goods=goodsService.getById(id);
        Long seller_id=goods.getSellerId();

        QueryWrapper<Seller> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",seller_id);
        Seller seller=sellerService.getOne(queryWrapper);

        String name=seller.getSellerName();
        if (StringUtils.isEmpty(name)) {
            throw new SssException(201, "数据信息为空");
        }

        return R.ok().data("people",name);
    }




}

